define(function (require, exports, module) {
    exports.ready = function () {
        require.async('$', function () {
            $(function () {
                require('layer');
                //require('swiper');
                loadPageJs();
                clkHrefNone();
            });
        });

    };
    require.async('fclick', function (layer) {
        FastClick.attach(document.body);
    });

    function clkHrefNone() {//点击href="#"的超链接  不会回到页面顶部
        $('body').on('click', 'a[href="#"]', function (e) {
            e.preventDefault();
        });
    }

    function loadPageJs() { //依赖注入
        //加载页面私有js
        $('[js]').each(function () {
            var js = $(this).attr('js').split('||');
            for (var i = 0, len = js.length; i < len; i++) {
                js[i] && require.async(js[i], function (exp) {
                    exp.ready && exp.ready();
                })
            }
        });
    }

    //一些公用的函数
    window.fm = {};
    fm.alert = function (msg, style, time, end) { //layer  alert  弹出提示 2秒后自动关闭
        msg.constructor === Array && (msg = msg.join('<br/>'));
        require.async('layer', function (layer) {
            layer.closeAll();
            layer.open({
                content: msg,
                style: style || 'background-color:#2db07e; text-align:center;color:#fff; border:none;',
                time: time || 1,
                end: end || function () {

                }
            });
        })
    };

    fm.confirm = function (msg,callback,style,btn) {
        msg.constructor === Array && (msg = msg.join('<br/>'));
        require.async('layer', function (layer) {
            layer.closeAll();
            layer.open({
                content: msg,
                style: style || 'min-width: 64%;',
                btn: btn || ['确认', '取消'],
                shadeClose: false,
                yes: function(){
                    callback(1);
                }, no: function(){
                    callback(0);
                }
            });
        })
    };

    fm.showLoging = function (text) { //显示加载中
        require.async('layer', function (layer) {
            layer.closeAll();
            var logIndex = layer.open({
                type: 2,
                shadeClose: false,
                content: text || '加载中...'
            });
            setTimeout(function () {
                layer.close(logIndex);
            }, 15000);
        })
    }

    fm.closeLayer = function (times) { //关闭加载中
        require.async('layer', function (layer) {
            if (times) {
                setTimeout(function () {
                    layer.closeAll();
                }, times * 500);
            } else {
                layer.closeAll();
            }

        })
    }

    fm.openFrame = function (src, cbk) {//弹出iframe
        require.async('layer', function (layer) {
            layer.closeAll();
            var index = layer.open({
                type: 1,
                content: '<iframe src="' + src + '" style="width:' + $(window).width() + 'px;height:' + $(window).height() + 'px;border:none"></iframe>',
                style: 'width:100%; height:' + document.documentElement.clientHeight + 'px; background-color:#FFF; border:none;',
            });
            cbk && cbk(index);
        })
    }
    fm.doFuns = function (ary, tms) {//执行很多函数  防止浏览器卡死
        ary.length && setTimeout(function () {
            ary.shift()();
            fm.doFuns(ary, tms);
        }, tms || 500);
    }
    fm.getUrlData = function (url, key) { //获取url中的数据
        url == location.href && (url = location.search);
        var re = new RegExp("[&,?]" + key + "=([^\\&]*)", "i");
        var a = re.exec(url);
        if (a == null) {
            return "";
        } else {
            return a[1];
        }
    }
    fm.popLayer = function (msg,icon,color) {
        $(function () {
            $('body').append('<div class="layerwraper"></div>');
            var html;
            html = '<div class="main">' +
            '<p class="iconfont ' + icon +' '+ color + '">' + '</p>' +
            '<p>' + msg + '</p>' +
            '</div>';
            $('.layerwraper').html(html).show();
            setTimeout(function () {
                $('.layerwraper').remove();
            }, 2000)
        });
    };


	fm.defaultalert = function (msg,type,time) {
		require.async('dfalert', function () {
			dfal({
				title: "",
				text: msg,
				type: type,
				timer: time,
				confirmButtonText: '确定'
			});
			$('.overlayer').show();
		})
	};
	fm.dfalertclose = function () {
		$('.da_toast').removeClass('showAlert');
		$('.overlayer').hide();
	};


});